define([ "app", "jquery", "md5", "ecb", "services/UserService",
		"resources/UserResource", "resources/AddYokiViewSpotResource",
		"resources/AddYokiCountryResource","resources/AddYokiCityResource" ],
		function(app) {

			var deps = [ "$scope", "$state", "$window", "$modalInstance", "$location", "$stateParams", "UserService", "UserResource", "AddYokiViewSpotResource","AddYokiCountryResource","AddYokiCityResource" ];

			function controller($scope, $state, $window, $modalInstance, $location, $stateParams, UserService, UserResource, AddYokiViewSpotResource,AddYokiCountryResource,AddYokiCityResource) {
				var pageNo = 1;
				var pageSize = 99999;
				initCountry();
				$scope.saveViewSpot = function() {
					//var file =$('#textfield').val();
					var formData = new FormData(document.forms.namedItem("fileinfo")); 
					/*if(file ==null || file==""){
						alert("请选中上传文件!");
						return;
					}*/
					
					AddYokiViewSpotResource.save($scope.viewSpotVo,formData).success(function(data){
						if (data.fileId) {
							$modalInstance.close($scope.viewSpotVo);
						}
		            });
				};

				$scope.close = function($scope,AddYokiViewSpotResource) {
					$modalInstance.close();
				};
				
				
				$scope.changeCountry =function (){
					var countryId =$scope.viewSpotVo.countryId;
					AddYokiCityResource.queryCityList(pageNo,pageSize,countryId).success(function(data){
						$scope.cityList = data.cityList;
						
		            });
				};
				/**
				 * 获取国家
				 */
				function initCountry(){
					AddYokiCountryResource.queryCountryList(pageNo,pageSize).success(function(data){
						$scope.countryList = data.countryList;
		            });
				}
			}
			controller.$inject = deps;
			return app.lazy.controller("AddViewSpotController", controller);
		});
